﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Syndication;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Xml;

namespace Jackie.Silverliight.SetpBySetp.RSSReader
{
    public partial class Reader : Page
    {
        public Reader()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void displayButton_Click(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(feedAddress.Text);
            WebRequest request = WebRequest.Create(uri);
            request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
        }

        void ResponseReady(IAsyncResult asyncResult)
        {
            WebRequest request = asyncResult.AsyncState as WebRequest;
            WebResponse response = request.EndGetResponse(asyncResult);

            XmlReader reader = XmlReader.Create(response.GetResponseStream());
            SyndicationFeed feed = SyndicationFeed.Load(reader);

            PostsList.ItemsSource = feed.Items;
        }

        private void fullScreenButton_Click(object sender, RoutedEventArgs e)
        {
            SyndicationItem item = PostsList.SelectedItem as SyndicationItem;

            Deatil.DataContext = item;
        }

        private void PostsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Content contentObject = Application.Current.Host.Content;
            contentObject.IsFullScreen = !contentObject.IsFullScreen;
        }

    }
}
